﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
namespace StreetSmartAdmin
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Login_Click(object sender, EventArgs e)
        {
            /*if (FormsAuthentication.Authenticate(txtUsername.Text, txtPassword.Text))
            {
                FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, false);
                Response.Redirect("Default.aspx");
            }
            else
            {
                //Response.Redirect("Login.aspx");
                lblStatus.Text = "Invalid username or password!";
            }
             */
            ADODotNetCRUD crud = new ADODotNetCRUD();
            Userinfo user = crud.ValidateUser(txtUsername.Text, txtPassword.Text);
            if (user!=null)
            {
                //Session.Add("UserInfo",user);
                //Session.Add("UserName", user.fullname);
                //Session.Add("LoginName", user.username);
                //Session.Add("Permission", user.permission);
                FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, false);
                if(user.groupname=="Manila")
                    Response.Redirect("MNL_Admin.aspx");
                else
                    Response.Redirect("Default.aspx");
            }
            else
            {
                lblStatus.Text = "Invalid username or password!";
            }
        }
    }
}